package com.example.springboot.service.Impl;

import com.example.springboot.entity.UserWatchRemember;
import com.example.springboot.entity.vo.PostVo;
import com.example.springboot.mapper.UserWatchRememberMapper;
import com.example.springboot.service.UserWatchRememberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserWatchRememberServiceImpl implements UserWatchRememberService {

    @Autowired
    private UserWatchRememberMapper userWatchRememberMapper;

    @Override
    public int addUserWatchRemember(UserWatchRemember userWatchRemember) {
        //获取当前时间赋值给UserwatchRemember
        userWatchRemember.setCreatedAt(new java.sql.Timestamp(System.currentTimeMillis()));
        userWatchRemember.setUpdatedAt(new java.sql.Timestamp(System.currentTimeMillis()));
        return userWatchRememberMapper.insert(userWatchRemember);
    }

    @Override
    public int deleteUserWatchRemember(int id) {
        return userWatchRememberMapper.deleteById(id);
    }

    @Override
    public int updateUserWatchRemember(UserWatchRemember userWatchRemember) {
        return userWatchRememberMapper.update(userWatchRemember);
    }

    @Override
    public UserWatchRemember getUserWatchRememberById(int id) {
        return userWatchRememberMapper.findById(id);
    }

    @Override
    public List<PostVo> getUserWatchRememberByUserId(Integer userId,Integer pageNum,Integer pageSize) {
        pageNum = (pageNum - 1) * pageSize;
        return userWatchRememberMapper.findByUserId(userId,pageNum,pageSize);
    }

    @Override
    public Integer getUserWatchRememberNumByUserId(int userId) {
        return userWatchRememberMapper.getUserWatchRememberNumByUserId(userId);
    }
}